public class AssembleException extends Exception {

	private static final long serialVersionUID = 1L;
	private Integer errType = null;
	private Integer lineNum = null;
	private String str = null;
	private String info = null;
	private Integer val1 = null;
	private Integer val2 = null;
	private String str1 = null;
	private String str2 = null;

	public AssembleException(int type, int lineNum, String str) {
		errType = type;
		this.str = str;
		this.lineNum = lineNum;
	}

	public AssembleException(int type) {
		errType = type;
	}

	public AssembleException(int type, int lineNum, String str, int val1,
			int val2) {
		this.val1 = val1;
		this.val2 = val2;
		errType = type;
		this.lineNum = lineNum;
		this.str = str;
	}

	public AssembleException(int type, int lineNum, String str, String str1,
			String str2) {
		this.str1 = str1;
		this.str2 = str2;
		errType = type;
		this.lineNum = lineNum;
		this.str = str;
	}

	public AssembleException(int type, String info) {
		this.errType = type;
		this.info = info;
	}

	public String toString() {

		switch (errType) {
		case 0:
			return info;
		case 1:// no .ORIG records
			return info = "No header information found at the first line of code.";
		case 2:// multiple def of symbols.
			return info = "Multiple symbol definition occurred at line "
					+ lineNum + " on symbol:" + str;
		case 3:// operation not legal
			return info = "Invalid operation at line " + lineNum
					+ ", the illegal operation is " + str;
		case 4:// operand number does not match opcode requirements
			if (str.equals(".END")) {
				return info = "Number of operands does not match the operation "
						+ str
						+ " at line "
						+ lineNum
						+ ", which should be at most "
						+ val2
						+ " but was "
						+ val1 + ".";
			} else {
				return info = "Number of operands does not match the operation "
						+ str
						+ " at line "
						+ lineNum
						+ ", which should be "
						+ val2 + " but was " + val1 + ".";
			}
		case 5:// operand value overflow
			return info = "Operand value overflow at line " + lineNum
					+ ",the violated value or symbol is " + str
					+ ". Legal value should be between " + str1 + " and "
					+ str2;

		case 6:// label should not started with R or x
			return info = "Symbol should not started with 'R' or 'x'."
					+ " The violated symbol is \"" + str + "\" at line "
					+ lineNum + ".";
		case 7:// undefined symbol
			info = "An undefined symbol was used at line " + lineNum
					+ ", the illegal symbol is \"" + str + "\".";

			if (str.charAt(0) == '=') {
				info = "Literal is used at non-LD operations at line "
						+ lineNum + ", the violated operand is \"" + str
						+ "\".";
			}
			return info;
		case 8:// should not use forward referencing with .BLKW and .EQU
			return info = "Forward referencing is used on .BLKW or .EQU at line "
					+ lineNum + ", the violated symbol is \"" + str + "\".";
		case 9:// String should enclosed in double quote.
			return info = "String is not enclosed in double quote at line "
					+ lineNum + ".";
		case 10:// value is not prefixed with 'x' or '#'
			return info = "A value is used without specifying hex or dec at line "
					+ lineNum + ", the value is \"" + str + "\".";
		case 11:// ops that require a symbol but not has one.
			return info = "Operation " + str + " at line " + lineNum
					+ " must has a symbol.";
		case 13:// must has .END operation at the end of source code. 
			return info = "There is no .END at the end of source code.";
		case 14:// No white spaces inside symbols.
			return info = "Symbol contains a whitespace at line " + lineNum
					+ ", the violated symbol is \"" + str + "\".";
			//TODO  starting point in this file that has been modified for lab3, update UG and PG plz.      
        case 15:// .EXT has duplicated symbols in the operands.                 
                return info = "There are duplicated symbols declared in the .EXT operands at line "+lineNum+", the symbol is \""+str+"\".";
        case 16://.ENT has duplicated symbols in the operands.       
                return info = "There are duplicated symbols declared in the .ENT operands at line "+lineNum+", the symbol is \""+str+"\".";
        case 17://.ENT and .EXT should not have labels.
                return info="Label was used on operator "+str+" at line "+lineNum +" ,.EXT and .ENT should not have labels.";
        //TODO end of modification in this file for lab3.
		default:
			break;

		}

		return info;

	}

}
